package com.atwy.business.service.Impl;

import com.atwy.business.feign.OrderFeign;
import com.atwy.business.feign.StorageFeign;
import com.atwy.business.service.BusinessService;
import com.atwy.common.RespBean;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BusinessServiceImpl implements BusinessService {
    @Autowired
    OrderFeign orderFeign;
    @Autowired
    StorageFeign storageFeign;

    @GlobalTransactional
    @Override
    public boolean purchase(String userId, String commodityCode, int count) {
        RespBean orderResp = orderFeign.order(userId, commodityCode, count);
        RespBean storageResp = storageFeign.storage(commodityCode, count);
        if(orderResp.getStatus().intValue() == 200 && storageResp.getStatus().intValue() == 200){
            return true;
        }
        return false;
    }
}
